﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Diagnostics;

namespace CityDistPhoneApp2
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ServiceReference1.DistServiceClient client = new ServiceReference1.DistServiceClient();

                client.GetDistCompleted += new EventHandler<ServiceReference1.GetDistCompletedEventArgs>(client_GetDistCompleted);

                if (textBox2.Text == textBox1.Text)
                           {
                              textBox2.Text = "";
                        }
                if ((textBox2.Text.Length != 0) && (textBox1.Text.Length != 0))
                {


                    client.GetDistAsync(textBox2.Text, textBox1.Text);
                    textBlock3.Text = "The distance in miles is ";
                }
            }
            catch (Exception e1)
            {
                textBlock4.Text = "";
                textBlock3.Text = e1.Message;
            }
            
        }
        void client_GetDistCompleted(object sender, ServiceReference1.GetDistCompletedEventArgs e) 
        {
           double d = (e.Result);
           textBlock4.Text = d.ToString();
           
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            textBlock4.Text = ""; 
            textBlock3.Text = "";

        }

       
        

        private void textBox2_TextChanged_1(object sender, TextChangedEventArgs e)
        {
            textBlock4.Text = "";
            textBlock3.Text = "";
        }


    }
}

